package thomas.javase.file;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.Test;

public class FileTest {

	@Test
	public void testParentList(){
		File folder = new File("C:/Users/Thomas/git/jaspersoft_studio/target/classes/reports/Demo1");
		List<String> subFileNames = new ArrayList<String>();
		Arrays.asList(folder.list()).forEach(fileName -> subFileNames.add(fileName.substring(0, fileName.lastIndexOf("."))));
		subFileNames.stream().filter(fileName -> ! "Demo1".equalsIgnoreCase(fileName))
				.collect(Collectors.toList()).forEach(e -> System.out.println(e));
	}

	@Test
	public void testFileNotFoundWhenSpaceInName() throws Exception{
		File file = new File("F:\\迅雷下载\\DaXiYang\\words\\Boardwalk Empire 01x01 BluRay 5.1 1080p x265 HEVC-Bytehare[UTR].ass");
		new FileReader(file);
		BufferedReader reader = new BufferedReader(new FileReader(file));
		System.out.println("finished");
	}

	// test FileUtil
	@Test
	public void testFileMove(){
		String sourceFolder = "F:\\temp\\test\\file\\source";
		String destinationFolder = "F:\\temp\\test\\file\\destination";
		int repeatTimes = 1000;
		int i = 0;
		while (true && i < repeatTimes) {
			FileUtil.fileMove(sourceFolder,destinationFolder );
			i++;
			try {
				Thread.currentThread().sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
